package com.travel.index.listener;

import com.travel.index.service.HotelIndexService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;


public class HotelIndexListener implements MessageListener {

	@Autowired
	private HotelIndexService hotelIndexService;

	@Override
	public void onMessage(Message message) {
		try {
			TextMessage textMessage = null;
			Integer hotelId = null;
			// 取商品id
			if (message instanceof TextMessage) {
				textMessage = (TextMessage) message;
				hotelId = Integer.parseInt(textMessage.getText());
			}
			// 向索引库添加文档
			hotelIndexService.doUpdateHotelIndex(hotelId);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
